public class Solution {
    public List<List<Integer>> combine(int n, int k) {
        List<Integer> temp = new ArrayList<>(k);
        List<List<Integer>> result = new ArrayList<>();
        comb(n, 0, k, temp, result);
        return result;
    }

    public void comb(int n,int s, int k,List<Integer> temp,List<List<Integer>> result){
        if(temp.size() == k ){
            result.add(new ArrayList<>(temp));
            return;
        }
        if(s + k - temp.size() > n)
            return;
        temp.add(s+1);
        comb(n, s+1, k, temp,result);
        temp.remove(temp.size()-1);
        comb(n, s+1, k, temp,result);
    }
    
}
